package com.cadre.web.controller.officer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cadre.common.utils.DateUtil;
import com.cadre.common.utils.R;
import com.cadre.system.domain.officer.Roster;
import com.cadre.system.service.RosterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"花名册接口"})
@RequestMapping({"/roster"})
@RestController
public class RosterController {

    @Resource
    private RosterService rosterService;


    @GetMapping({"/GetRosterResponseAll"})
    @ApiOperation("获取全部花名册列表")
    public R GetRosterResponseAll(){
        return R.ok().put("data",rosterService.list(new LambdaQueryWrapper<Roster>().orderByDesc(Roster::getCreatTime)));
    }

    @PostMapping({"/addRosrer"})
    @ApiOperation("添加花名册")
    public R addRosrer(@RequestBody Roster roster){
        roster.setCreatTime(DateUtil.getCurrDate(DateUtil.FORMAT_ONE));
        return R.ok().put("data",rosterService.save(roster));
    }
    @GetMapping({"/deletRosrer/{id}"})
    @ApiOperation("删除花名册")
    public R deletRosrer(@PathVariable String id){
        return R.ok().put("data",rosterService.removeById(id));
    }
    @PostMapping({"/updateRosrer"})
    @ApiOperation("根据ID更新花名册人员")
    public R updateRosrer(@RequestBody Roster roster){
        LambdaUpdateWrapper<Roster> rosterKeysQueryWrapper = new LambdaUpdateWrapper<>();
        rosterKeysQueryWrapper.set(Roster::getPersonids,roster.getPersonids());
        rosterKeysQueryWrapper.eq(Roster::getFlowid,roster.getFlowid());
        return R.ok().put("data",rosterService.update(rosterKeysQueryWrapper));
    }


}
